package com.intellagric.controller.module.cms_content;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.pojo.CmsCategory;
import com.intellagric.service.module.cms_content.ContentCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.UUID;

/**
 * @Auther: zhy
 * @Date: 2018/10/19
 * @Description: 前台网站内容分类管理
 */
@Controller
public class ContentCategoryController {

    @Autowired
    private ContentCategoryService contentCategoryService;

    /**
     * 添加内容分类信息
     * @Param contentCategory
     * @return ResponseMessage
     */
    @RequestMapping("/contentCatogory/add")
    @ResponseBody
    public ResponseMessage add(CmsCategory contentCategory) {
        contentCategory.setId(UUID.randomUUID().toString().replaceAll("-",""));
        return contentCategoryService.addContentCategory(contentCategory);
    }


    /**
     * 删除内容分类信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/contentCatogory/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return contentCategoryService.deleteContentCategory(id);
    }

    /**
     * 修改信息
     * @Param contentCategory
     * @return ResponseMessage
     */
    @RequestMapping("/contentCatogory/edit")
    @ResponseBody
    public ResponseMessage edit(CmsCategory contentCategory) {
        return contentCategoryService.editContentCategory(contentCategory);
    }

    /**
     * 查询内容分类信息
     * @Param id
     * @return Object
     */
    @RequestMapping("/contentCatogory/detail/{id}")
    @ResponseBody
    public CmsCategory get(@PathVariable String id) {
        return contentCategoryService.queryContentCategoryById(id);
    }

    /**
     * 查询内容分类树信息
     * @return LayuiDataGridResult
     */
    @RequestMapping("/contentCatogory/tree")
    @ResponseBody
    public LayuiDataGridResult getTree() {
        return contentCategoryService.getContentCategoryTree();
    }

    /**
     * 查询内容分类树信息
     * @return List<ContentCategory>
     */
    @RequestMapping("/contentCatogory/tree/select")
    @ResponseBody
    public List<CmsCategory> getTreeSelect() {
        List<CmsCategory> contentCategoryTree = contentCategoryService.getContentCategoryTree().getData();
        return contentCategoryTree;
    }

    /**
     * 查询内容分类信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/contentCatogory/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return contentCategoryService.queryContentCategoryList();
    }

    /**
     * 异步查询内容分类信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/contentCatogory/query/{parentId}")
    @ResponseBody
    public LayuiDataGridResult getListByParentId(@PathVariable String parentId) {
        return contentCategoryService.queryContentCategoryByPid(parentId);
    }

}
